package cn.ffcs.unm.application.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.application.dao.ApplicationDao;
import cn.ffcs.unm.application.model.DistributedApplicationChild;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("applicationDao")
public class ApplicationDaoImpl extends BaseDaoImpl implements ApplicationDao {

	@Override
	public PageInfo queryPageInfoByDistributedApplicationChild(DistributedApplicationChild distributedApplicationChild,
			int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select * FROM VIE_WA_PAYROLL V WHERE 1 = 1 ");
		
		List<Object> params = new ArrayList<Object>();
		if (null != distributedApplicationChild) {
			if (!StrUtil.isEmpty(distributedApplicationChild.getMonthId())) {
				sb.append(" AND V.monthId = ? ");
				params.add(distributedApplicationChild.getMonthId());
			}
			if (!StrUtil.isEmpty(distributedApplicationChild.getBillCode())) {
				sb.append(" AND V.BILLCODE LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(distributedApplicationChild.getBillCode())
						+ "%");
			}
			if (!StrUtil.isEmpty(distributedApplicationChild.getBillName())) {
				sb.append(" AND V.BILLNAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(distributedApplicationChild.getBillName())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, DistributedApplicationChild.class);
	}
}
